/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.zx.points.rule.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.zx.points.rule.entity.TpointsRule;
import com.jeesite.modules.zx.points.rule.service.TpointsRuleService;

/**
 * 积分规则表Controller
 * @author zpp
 * @version 2020-02-13
 */
@Controller
@RequestMapping(value = "${adminPath}/zx/points/rule/tpointsRule")
public class TpointsRuleController extends BaseController {

	@Autowired
	private TpointsRuleService tpointsRuleService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public TpointsRule get(String id, boolean isNewRecord) {
		return tpointsRuleService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("zx:points:rule:tpointsRule:view")
	@RequestMapping(value = {"list", ""})
	public String list(TpointsRule tpointsRule, Model model) {
		model.addAttribute("tpointsRule", tpointsRule);
		return "modules/zx/points/rule/tpointsRuleList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("zx:points:rule:tpointsRule:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<TpointsRule> listData(TpointsRule tpointsRule, HttpServletRequest request, HttpServletResponse response) {
		tpointsRule.setPage(new Page<>(request, response));
		Page<TpointsRule> page = tpointsRuleService.findPage(tpointsRule);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("zx:points:rule:tpointsRule:view")
	@RequestMapping(value = "form")
	public String form(TpointsRule tpointsRule, Model model) {
		model.addAttribute("tpointsRule", tpointsRule);
		return "modules/zx/points/rule/tpointsRuleForm";
	}

	/**
	 * 保存积分规则表
	 */
	@RequiresPermissions("zx:points:rule:tpointsRule:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated TpointsRule tpointsRule) {
		tpointsRuleService.save(tpointsRule);
		return renderResult(Global.TRUE, text("保存积分规则表成功！"));
	}
	
	/**
	 * 停用积分规则表
	 */
	@RequiresPermissions("zx:points:rule:tpointsRule:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(TpointsRule tpointsRule) {
		tpointsRule.setStatus(TpointsRule.STATUS_DISABLE);
		tpointsRuleService.updateStatus(tpointsRule);
		return renderResult(Global.TRUE, text("停用积分规则表成功"));
	}
	
	/**
	 * 启用积分规则表
	 */
	@RequiresPermissions("zx:points:rule:tpointsRule:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(TpointsRule tpointsRule) {
		tpointsRule.setStatus(TpointsRule.STATUS_NORMAL);
		tpointsRuleService.updateStatus(tpointsRule);
		return renderResult(Global.TRUE, text("启用积分规则表成功"));
	}
	
	/**
	 * 删除积分规则表
	 */
	@RequiresPermissions("zx:points:rule:tpointsRule:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(TpointsRule tpointsRule) {
		tpointsRuleService.delete(tpointsRule);
		return renderResult(Global.TRUE, text("删除积分规则表成功！"));
	}
	
}